package com.zeta.eduservice.controller.file;


import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.itextpdf.text.DocumentException;
import com.zeta.eduservice.entity.EduCreateFile;
import com.zeta.eduservice.entity.vo.front.ChapterCourseDetialVo;
import com.zeta.eduservice.entity.vo.front.QuestionCreateInfo;
import com.zeta.eduservice.entity.vo.front.front.PaperInfoVo;
import com.zeta.eduservice.entity.yml.TeacherFileYml;
import com.zeta.eduservice.service.EduCreatePdfService;
import com.zeta.eduservice.utils.Download;

/**
 * <p>
 * 生成习题pdf 前端控制器
 * </p>
 *
 * @author zeta
 * @since 2020-10-14
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/edu_create_pdf")
public class EduCreatePdfController {
   @Autowired
    private TeacherFileYml teacherFileYml;
	@Autowired
	EduCreatePdfService pdfService;
	@Autowired
	Download downUtil;
	@PostMapping("{teaId}/{folderId}/{fileName}")
	public void createQuestionPdf(@PathVariable String teaId,@PathVariable String folderId,@PathVariable String fileName,
			HttpServletResponse Response) throws IOException {
		EduCreateFile eduCreatePdf = new EduCreateFile();
		eduCreatePdf.setTeaid(teaId);
		eduCreatePdf.setFilename(fileName);
	
		eduCreatePdf.setExt("pdf");
		String path=teacherFileYml.getFilePath();
		File file = new File(path);
		if(!file.exists()){//如果文件夹不存在
			file.mkdir();//创建文件夹
		}
		eduCreatePdf.setPath(path);
		String pdfDownloadPath = path+"/"+fileName+".docx";

		pdfService.create(eduCreatePdf,pdfDownloadPath);
		downUtil.fileDownLoad(pdfDownloadPath, Response);
	}
	
	
	
}

